"""
@Project:Python crawler
@File:迭代器.py
@Author:邓建祥
@Date:10:08
"""

class MYNumbers:
    def __iter__(self):
        self.a = 1
        return self

    def __next__(self):
        if self.a <= 20: # 限定20次
            x= self.a
            self.a += 1
            return x
        else:
            raise StopIteration

myclass = MYNumbers()
myiter = iter(myclass)

for x in myiter:
    print(x)